package com.example.testdemo.manager;

import org.andengine.engine.camera.Camera;
import org.andengine.engine.camera.ZoomCamera;
import org.andengine.engine.options.ScreenOrientation;

import android.graphics.Point;
import android.util.SparseArray;

public class CamerasManager {
	public final static int CAMERA_NORMAL = 1;
	public final static int CAMERA_ZOOM = 2;

	private class RESOLUTION_NORMAL_DEVICE {
		public final static int WIDTH = 360;
		public final static int HEIGHT = 592;
	}

	@SuppressWarnings("unused")
	private class RESOLUTION_HEIGHT_DEVICE {
		public final static int WIDTH = 720;
		public final static int HEIGHT = 1184;
	}

	public final static ScreenOrientation ORIENTATION = ScreenOrientation.LANDSCAPE_FIXED;
	public final static Point SCREEN_RESOLUTION = new Point();

	private static CamerasManager INSTANCE = null;

	private SparseArray<Camera> mCameraMap = new SparseArray<Camera>();

	private CamerasManager() {
		if (ORIENTATION == ScreenOrientation.LANDSCAPE_FIXED) {
			SCREEN_RESOLUTION.x = RESOLUTION_NORMAL_DEVICE.HEIGHT;
			SCREEN_RESOLUTION.y = RESOLUTION_NORMAL_DEVICE.WIDTH;
		} else if (ORIENTATION == ScreenOrientation.PORTRAIT_FIXED) {
			SCREEN_RESOLUTION.x = RESOLUTION_NORMAL_DEVICE.WIDTH;
			SCREEN_RESOLUTION.y = RESOLUTION_NORMAL_DEVICE.HEIGHT;
		}
	}

	public static CamerasManager getInstance() {
		if (INSTANCE == null)
			INSTANCE = new CamerasManager();
		return INSTANCE;
	}

	public void initCamera(int whichCamera) {
		switch (whichCamera) {
		case CAMERA_NORMAL:
			break;
		case CAMERA_ZOOM:
			mCameraMap.put(whichCamera, new ZoomCamera(0, 0,
			        SCREEN_RESOLUTION.x, SCREEN_RESOLUTION.y));
			break;
		}
	}

	public Camera getCamera(int whichCamera) {
		return mCameraMap.get(whichCamera);
	}

	public void free() {
		mCameraMap.clear();
		INSTANCE = null;
	}
}
